package cn.sixmillions.wiki.common.handler;

import cn.sixmillions.wiki.common.enums.IResultCode;
import cn.sixmillions.wiki.common.enums.ResultCodeEnum;

/**
 * @description: 自定义系统异常类
 * @author: sixmillions
 * @since: 2021/06/04
 **/
public class ServiceException extends RuntimeException {
    private static final long serialVersionUID = 2359767895161832954L;

    private final IResultCode resultCode;

    private String errorCode;

    public ServiceException(String message) {
        super(message);
        this.resultCode = ResultCodeEnum.FAILURE;
    }

    public ServiceException(IResultCode resultCode) {
        super(resultCode.getMessage());
        this.resultCode = resultCode;
    }

    public ServiceException(IResultCode resultCode, Throwable cause) {
        super(cause);
        this.resultCode = resultCode;
    }

    public ServiceException(String errorCode, String message) {
        super(message);
        this.resultCode = ResultCodeEnum.FAILURE;
        this.errorCode = errorCode;
    }

    @Override
    public Throwable fillInStackTrace() {
        return this;
    }

    public Throwable doFillInStackTrace() {
        return super.fillInStackTrace();
    }

    public IResultCode getResultCode() {
        return this.resultCode;
    }

    public String getErrorCode() {
        return this.errorCode;
    }
}
